var Model = require('../model/user_model');

class UserController {
    Login(data, callback) {
        let m = new Model()
        if (data.user_name == undefined || data.pass_word == undefined) {
            callback(undefined, { code: 400, msg: '用户名或密码不能为空', data: {} })
            return;
        }
        m.Detail(data, callback)
    }

    Regist(data, callback) {
        let m = new Model()
        if (data.user_name == undefined) {
            callback(undefined, { code: 400, msg: '用户名不能为空', data: {} })
            return;
        }
        m.Add(data, callback)
    }

    Update(data, callback) {
        let m = new Model()
        if (data.uid == undefined) {
            callback(undefined, { code: 400, msg: '用户名id不能为空', data: {} })
            return;
        }
        m.Update(data, callback)
    }

    List(data, callback) {
        let m = new Model()

        if (data.page_size == undefined) {
            data.page_size = 20
        }

        if (data.page == undefined) {
            data.page = 0
        }
        m.List(data, callback)
    }

    Detail(data, callback) {
        let m = new Model()
        if (data.uid == undefined) {
            callback(undefined, { code: 400, msg: '用户名id不能为空', data: {} })
            return;
        }
        m.Detail(data, callback)
    }

}

module.exports = UserController